package cn.net.cfss.fgbp.provider.manage.biz;

import cn.net.cfss.fgbp.base.common.biz.BaseBiz;
import cn.net.cfss.fgbp.provider.manage.dao.FscTenantUserDtoMapper;
import cn.net.cfss.fgbp.spi.manage.dto.FscTenantDto;
import cn.net.cfss.fgbp.spi.manage.dto.FscTenantUserDto;
import cn.net.cfss.fgbp.spi.manage.vo.FscTenantUserVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author wutao
 * @version 1.0
 * @date 2020/9/11 14:58
 */
@Slf4j
@Service
public class FscTenantUserBiz extends BaseBiz<FscTenantUserDtoMapper, FscTenantUserDto> {
    public Map<Long, String> queryNameByUserIds(List<Long> userIds) {
        if (userIds == null || userIds.isEmpty()) {
            return new HashMap<>();
        }
        List<FscTenantUserVo > list = mapper.queryNameByUserIds(userIds);
        Map<Long, String> result = new HashMap<>();
        for (FscTenantUserVo fscTenantUserVo : list) {
            result.put(fscTenantUserVo.getUserId(), fscTenantUserVo.getTenantName());
        }
        return result;
    }

    public FscTenantUserVo queryByUserid(Long userId) {
        return mapper.queryByUserid(userId);
    }

    public Map<Long, FscTenantDto> queryTenantByUserIds(List<Long> userIds) {
        if (userIds == null || userIds.isEmpty()) {
            return new HashMap<>();
        }
        List<FscTenantUserVo > list = mapper.queryNameByUserIds(userIds);
        Map<Long, FscTenantDto> result = new HashMap<>();
        for (FscTenantUserVo fscTenantUserVo : list) {
            FscTenantDto fscTenantDto = new FscTenantDto();
            fscTenantDto.setId(fscTenantUserVo.getTenantId());
            fscTenantDto.setTenantName(fscTenantUserVo.getTenantName());
            result.put(fscTenantUserVo.getUserId(), fscTenantDto);
        }
        return result;
    }


    public void deleteByUserId(FscTenantUserDto fscTenantUserDto) {
        mapper.deleteByUserId(fscTenantUserDto);
    }
}
